package www.openteam.com.model.business.other;


import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.PeopleGroup;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/5/2.
 */

public class WOSearchModel extends BaseModel {


    private boolean isQueryS = false;

    private boolean isQueryB = false;


    public boolean findPeopleGroup(String code, int pageSize, final WOSearchOnListener woSearchOnListener) {

        httpApiService.findPeopleGroup(code, pageSize)
                .compose(new CommonTransformer<PeopleGroup>())
                .subscribe(new CommonSubscriber<PeopleGroup>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(PeopleGroup peopleGroup) {
                        isQueryS = true;
                        woSearchOnListener.suceessSInfo(peopleGroup);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        isQueryS = false;
                        woSearchOnListener.failSInfo(e.message);
                    }
                });


        return isQueryS;
    }


    public boolean findBanzu(String code, int pageSize, final WOSearchBOnListener woSearchBOnListener) {

        httpApiService.findBanzu(code, pageSize)
                .compose(new CommonTransformer<PeopleGroup>())
                .subscribe(new CommonSubscriber<PeopleGroup>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(PeopleGroup banGroup) {
                        isQueryB = true;
                        woSearchBOnListener.suceessBInfo(banGroup);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQueryB= false;
                        woSearchBOnListener.failBInfo(e.message);
                    }
                });

            return isQueryB;
    }

    public interface WOSearchOnListener {

        void suceessSInfo(PeopleGroup peopleGroup);

        void failSInfo(String error);


    }

    public interface WOSearchBOnListener {

        void suceessBInfo(PeopleGroup banGroup);

        void failBInfo(String error);


    }


}
